/*
 * ESPRESSIF MIT License
 *
 * Copyright (c) 2019 <ESPRESSIF SYSTEMS (SHANGHAI) CO., LTD>
 *
 * Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
 * it is free of charge, to any person obtaining a copy of this software and associated
 * documentation files (the "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the Software is furnished
 * to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or
 * substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 */

#ifndef _BOARD_PINS_CONFIG_H_
#define _BOARD_PINS_CONFIG_H_

#include "driver/i2c.h"
#include "driver/i2s_std.h"
#include "driver/i2s_pdm.h"
#include "driver/i2s_tdm.h"
#include "driver/i2s_types_legacy.h"
#include "driver/spi_common.h"
#include "driver/spi_master.h"
#include "driver/spi_slave.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
 * @brief Audio Codec Chip Function Definition
 */
// #define I2S_BCK_IO      (GPIO_NUM_36)
// #define I2S_WS_IO       (GPIO_NUM_35)
// #define I2S_DO_IO       (GPIO_NUM_37)
#define I2S_MCK_IO      (-1)        /* 0 From MCLK of esp32   1 From BCLK */
#define I2S_BCK_IO      (GPIO_NUM_14)
#define I2S_WS_IO       (GPIO_NUM_21)
#define I2S_DO_IO       (GPIO_NUM_13)
#define I2S_DI_IO       (-1)
#define PA_CTR_IO       (-1)

typedef enum {
    AUDIO_CTRL_NONE = 0,
    AUDIO_CTRL_LAST,       /* 上一首 */ 
    AUDIO_CTRL_PLAY,       /* 播放指定的一首 */ 
    AUDIO_CTRL_NEXT,       /* 下一首 */ 
    AUDIO_CTRL_RUNNING,    /* 正在播放 */ 
    AUDIO_CTRL_PAUSED,     /* 暂时播放 */ 
} audio_ctrl_t;

typedef struct {
#define MP3_FILE        0       // MP3音乐
#define AUDIO_FILE      1       // 语音提示音
    audio_ctrl_t ctrl;
    uint8_t music; 
    uint8_t file;   // 选择音频文件
} play_info_t;

void audio_adf_init(void);
void audio_music_play_audio(uint8_t music);
void audio_music_play_mp3(uint8_t music);
void audio_music_play_ctrl(audio_ctrl_t ctrl);
void audio_music_set_volume(uint8_t volume);
uint8_t audio_music_get_volume(void);

//====================================================================================================
//文件夹01 -- 通用操作
#if 1
#define VOICE_COMM_POWER_ON             0   //开机音乐
#define VOICE_COMM_WIFI_PAIR            1   //开始配网
#define VOICE_COMM_WIFI_PAIR_OK         2   //配网成功
#define VOICE_COMM_WIFI_PAIR_FAIL       3   //配网失败
#define VOICE_COMM_WIFI_CONNECT_FAIL    4   //网络连接失败
#define VOICE_COMM_WIFI_CONNECT_OK      5   //网络已连接
#define VOICE_COMM_WIFI_DISCONNECT      6   //网络未连接
#define VOICE_COMM_SERVER_CONNECT_FAIL  7   //服务器连接失败
#define VOICE_COMM_SERVER_CONNECT_OK    8   //服务器连接成功
#define VOICE_COMM_SERVER_DISCONNECT    9   //服务器断开
#define VOICE_COMM_WIFI_CONNECTING      10  //正在连接网络
#define VOICE_COMM_POWER_DOWN           11  //设备关机
#define VOICE_COMM_OTA                  12  //升级提示
#define VOICE_COMM_OTA_OK               13  //升级完成
#define VOICE_COMM_TUBLE_WARING         14  //有人跌倒
#define VOICE_COMM_CALL_OUT             15  //有人呼叫
#else 
#define VOICE_COMM_POWER_ON             11   //开机音乐
#define VOICE_COMM_WIFI_PAIR            12   //开始配网
#define VOICE_COMM_WIFI_PAIR_OK         13   //配网成功
#define VOICE_COMM_WIFI_PAIR_FAIL       14   //配网失败
#define VOICE_COMM_WIFI_CONNECT_FAIL    15   //网络连接失败
#define VOICE_COMM_WIFI_CONNECT_OK      0   //网络已连接
#define VOICE_COMM_WIFI_DISCONNECT      1   //网络未连接
#define VOICE_COMM_SERVER_CONNECT_FAIL  2   //服务器连接失败
#define VOICE_COMM_SERVER_CONNECT_OK    3   //服务器连接成功
#define VOICE_COMM_SERVER_DISCONNECT    4  //服务器断开
#define VOICE_COMM_WIFI_CONNECTING      5  //正在连接网络
#define VOICE_COMM_POWER_DOWN           6  //设备关机
#define VOICE_COMM_OTA                  7  //升级提示
#define VOICE_COMM_OTA_OK               8  //升级完成
#define VOICE_COMM_TUBLE_WARING         9  //有人跌倒
#define VOICE_COMM_CALL_OUT             10  //有人呼叫
#endif
 

/**
 * @brief                  Get i2c pins configuration
 *
 * @param      port        i2c port number to get configuration
 * @param      i2c_config  i2c configuration parameters
 *
 * @return
 *     - ESP_OK
 *     - ESP_FAIL
 */
esp_err_t get_i2c_pins(i2c_port_t port, i2c_config_t *i2c_config);

/**
 * @brief                  Get i2s pins configuration
 *
 * @param      port        i2s port number to get configuration
 * @param      i2s_config  i2s configuration parameters
 *
 * @return
 *     - ESP_OK
 *     - ESP_FAIL
 */
esp_err_t get_i2s_pins(i2s_port_t port, i2s_pin_config_t *i2s_config);

/**
 * @brief                  Get spi pins configuration
 *
 * @param      spi_config                   spi bus configuration parameters
 * @param      spi_device_interface_config  spi device configuration parameters
 *
 * @return
 *     - ESP_OK
 *     - ESP_FAIL
 */
esp_err_t get_spi_pins(spi_bus_config_t *spi_config, spi_device_interface_config_t *spi_device_interface_config);

/**
 * @brief Set i2s mclk output pin
 *
 * @note GPIO1 and GPIO3 default are UART pins.
 *
 * @param i2s_num       i2s port index
 * @param gpio_num      gpio number index, only support GPIO0, GPIO1 and GPIO3.

 * @return
 *     - ESP_OK                     Success
 *     - ESP_ERR_INVALID_ARG        Parameter error
 *     - ESP_ERR_INVALID_STATE      Driver state error
 *     - ESP_ERR_ADF_NOT_SUPPORT    Not support
 */
esp_err_t i2s_mclk_gpio_select(i2s_port_t i2s_num, gpio_num_t gpio_num);

/**
 * @brief  Get the gpio number for PA enable
 *
 * @return  -1      non-existent
 *          Others  gpio number
 */
int8_t get_pa_enable_gpio(void);

/**
 * @brief Get number for set function
 *
 * @return -1       non-existent
 *         Others   number
 */
int8_t get_input_set_id(void);

/**
 * @brief Get number for play function
 *
 * @return -1       non-existent
 *         Others   number
 */
int8_t get_input_play_id(void);

/**
 * @brief number for volume up function
 *
 * @return -1       non-existent
 *         Others   number
 */
int8_t get_input_volup_id(void);

/**
 * @brief Get number for volume down function
 *
 * @return -1       non-existent
 *         Others   number
 */
int8_t get_input_voldown_id(void);

/**
 * @brief Get green led gpio number
 *
 * @return -1       non-existent
 *        Others    gpio number
 */
int8_t get_reset_codec_gpio(void);

/**
 * @brief Get DSP reset gpio number
 *
 * @return -1       non-existent
 *         Others   gpio number
 */
int8_t get_reset_board_gpio(void);


#ifdef __cplusplus
}
#endif

#endif
